package com.situ.storehouse.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登录过滤器
@WebFilter("/*")
public class LogininFilter implements Filter{

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		
		HttpServletRequest req=(HttpServletRequest) request;
		String url=req.getRequestURI();
		Boolean isLogin=req.getSession().getAttribute("currentAttendant")!=null;
		if(isLogin||url.equals("/login") || url.startsWith("/css/") || url.startsWith("/js/")|| url.startsWith("/lib/")
				|| url.startsWith("/images/") || url.startsWith("/image")) {
			chain.doFilter(request, response);
		}else {
			HttpServletResponse resp=(HttpServletResponse)response;
			resp.sendRedirect("/login");
		}
	}

}
